home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6179 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to the size of a file in C ?
  5. Date: 10 Feb 1996 20:12:35 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4fiu7j$ikl@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe8.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Feb 09, 1996 12:31:06 in article <How to the size of a file in C ?>,
  15. 'Gilbert Banks <gilbertb@bnr.ca>' wrote: 
  16.  
  17.  
  18. >How do I get the size of a file in C UNIX-based?  I tried sizeof <file>,
  19. but  
  20. >that only returns the size of the object called "<file>" and not the data.
  21.  
  22. >I know about filelength(), also, but that is DOS, Windows, and OS/2. 
  23. There are other (better?) ways, but the one that has worked 
  24. for me for many years , and is portable across the platforms 
  25. mentioned plus some: 
  26.  
  27. 1.  Open the file in binary mode fopen("foo.bar", "rb"); 
  28. 2.  Move the file pointer to its end using fseek(); 
  29. 3.  Query the file position with ftell(); 
  30. 4.  Either close (fclose()) or rewind the file with fseek(). 
  31.  
  32. I've also used a c++ version with fstreams using seekg 
  33. and tellg but have not had a chance to test it on Unix 
  34. platforms other than Solaris 2.3. 
  35.  
  36. -- 
  37. Pete Grant 
  38. Kalevi, Inc. 
  39. Object Oriented Software Development
  40.